package test.com.googlecode.likesql.converter;

import junit.framework.TestCase;

import com.googlecode.likesql.converter.LikeExpConverter;
import com.googlecode.likesql.expression.LikeExp;

public class LikeExpTester extends TestCase {
	
	private LikeExpConverter likeCvt;
	
	public void setUp(){
		likeCvt=new LikeExpConverter();
	}
	
	public void tearDown(){
		likeCvt=null;
	}
	
	public void testBasicLikeSql(){
		LikeExp exp=LikeExp.like("abc_%");
		assertEquals("'abc_%'",likeCvt.toSql(exp));
		assertEquals("?",likeCvt.toTemplate(exp));
	}
	
	public void testStartWith(){
		LikeExp exp=LikeExp.startWith("abc");
		assertEquals("'%abc'",likeCvt.toSql(exp));
		assertEquals("?",likeCvt.toTemplate(exp));
	}
	
	public void testEndWith(){
		LikeExp exp=LikeExp.endWith("abc");
		assertEquals("'abc%'",likeCvt.toSql(exp));
		assertEquals("?",likeCvt.toTemplate(exp));
	}
	
	public void testInAnywhere(){
		LikeExp exp=LikeExp.inAnywhere("abc");
		assertEquals("'%abc%'",likeCvt.toSql(exp));
		assertEquals("?",likeCvt.toTemplate(exp));
	}
	
	public void testEscape(){
		LikeExp exp=LikeExp.like("ab_c!%").escape('!');
		assertEquals("'ab_c!%' ESCAPE '!'",likeCvt.toSql(exp));
		assertEquals("? ESCAPE ?",likeCvt.toTemplate(exp));
	}
}
